

/**
 * ExpressionTreeOp represents an element in an expression tree.
 * 
 * @author Lewis and Chase
 * @version 4.0
 */
public class ExpressionTreeOp 
{
    private int termType;
    private char operator;
    private Variable value;
    private Step step;

    /**
     * Creates a new expression tree object with the specified data.
     *
     * @param type the integer type of the expression
     * @param op   the operand for the expression
     * @param val  the value for the expression
     */
    public ExpressionTreeOp(int type, char op, Variable val) 
    {
        termType = type;
        operator = op;
        value = val;
        step = null;
    }
    
    /**
     * Set up the Step object for ExpressionTreeOp.
     * @param step Step object in this ExpressionTreeOp
     */
    public void setStep(Step step){
    	this.step = step;
    }
    
    /**
     * Return the Step object for ExpressionTreeOp.
     * @return Step object in this ExpressionTreeOp
     */
    public Step getStep(){
    	return step;
    }
    
    /**
     * Return true if this object has a step and false otherwise.
     * @return true if this object has a step, false otherwise
     */
    public boolean hasStep(){
    	return (step != null);
    }

    /**
     * Returns true if this object is an operator and false otherwise.
     *
     * @return true if this object is an operator, false otherwise
     */
    public boolean isOperator() 
    {
        return (termType == 1);
    }
    
    /**
     *Returns the operator of this expression tree object.
     *
     * @return the character representation of the operator
     */
    public char getOperator() 
    {
        return operator;
    }
    
    /**
     * Returns the integer representative of this expression tree object.
     *
     * @return the integer value of this expression tree object
     */
    public int getValueInInt(){
    	return value.getInteger();
    }
    
    /**
     * Set the Variable value of ExpressionTreeOp
     * @param value the Variable class to be set into the ExpressionTreeOp
     */
    public void setValue(Variable value){
    	this.value = value;
    }
    
    /**
     * Return the operator or variable characters only but not variable values, the inputed 
     * integer will be displayed also
     * @return string values for the operator, variable character or integer inputed
     */
    public String toStringInCharacter()
    {
        if (termType == 1) 
            return operator + "";
        else
        	return value.getCharacter();
    }
    
    /**
     * Return the operator or variable values if exist, the inputed integer will displayed also
     * @return string values for the operator, variable value or integer inputed
     */
    public String toString(){    	
    	if (termType == 1) 
            return operator + "";
        else{
        	if (value.getInteger() == null)
        		return value.getCharacter();
        	else
        		return value.getInteger().toString();
        }
    }
}
    

